#!/bin/bash

set -e

echo "Building sample APK..."

cd "$(dirname "$0")"

./gradlew sample:clean
./gradlew sample:assembleDebug

APK_OUTPUT_DIR="output/apk"
mkdir -p "$APK_OUTPUT_DIR"

APK_FILE=$(find sample -name "*.apk" -path "*/outputs/apk/*" | head -1)

if [ -n "$APK_FILE" ]; then
    cp "$APK_FILE" "$APK_OUTPUT_DIR/"
    echo "✓ APK built successfully: $APK_OUTPUT_DIR/$(basename $APK_FILE)"
else
    echo "✗ APK file not found"
    exit 1
fi
